package route

import (
	"com.haojuetrace/actualCombat/controller"
	"com.haojuetrace/actualCombat/middleware"
	"github.com/gin-gonic/gin"
)

/*
 gin路由表
*/
func CollectRoute(r *gin.Engine) *gin.Engine {
	r.Use(middleware.CORSMiddeware)
	//用户相关路由
	userGroup := r.Group("/api/auth")
	userGroup.POST("register", controller.Register)
	userGroup.POST("login", controller.Login)
	userGroup.GET("info", middleware.AuthMiddleware, controller.Info)
	//分类路由
	classifyGroup := r.Group("classify")
	classifyController := controller.NewClassifyController()
	classifyGroup.POST("", classifyController.Create)
	classifyGroup.PUT("/:id", classifyController.Updata)
	classifyGroup.GET("/:id", classifyController.Show)
	classifyGroup.DELETE("/:id", classifyController.Delete)
	//文章路由
	postGroup := r.Group("/posts")
	postGroup.Use(middleware.AuthMiddleware)
	postController := controller.NewPostController()
	postGroup.POST("", postController.Create)
	postGroup.PUT("/:id", postController.Updata)
	postGroup.GET("/:id", postController.Show)
	postGroup.GET("", postController.List)
	postGroup.DELETE("/:id", postController.Delete)
	return r
}
